package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Detailsinfo;
import com.ysd.entity.ProductclassifiCationTable;
import com.ysd.util.DBManager;

public class xinwenDaoImpl {
	public List<Detailsinfo>  xin(int pid) {
		List<Detailsinfo> list= new ArrayList<Detailsinfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from detailsinfo where newsId="+pid);
					while (rs.next()) {
						String nt = rs.getString("nt");
						int newsId = rs.getInt("newsId");
						String newsTitle = rs.getString("newsTitle");
						String newsDetails = rs.getString("newsDetails");
						int consultationId = rs.getInt("consultationId");
						Detailsinfo xinlist = new Detailsinfo(newsId, newsTitle, newsDetails, consultationId,nt);
						list.add(xinlist);
					}
					return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	public List<Detailsinfo>  xinwenxiangqing() {
		List<Detailsinfo> list= new ArrayList<Detailsinfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from detailsinfo");
					while (rs.next()) {
						String nt = rs.getString("nt");
						int newsId = rs.getInt("newsId");
						String newsTitle = rs.getString("newsTitle");
						String newsDetails = rs.getString("newsDetails");
						int consultationId = rs.getInt("consultationId");
						Detailsinfo xinlist = new Detailsinfo(newsId, newsTitle, newsDetails, consultationId,nt);
						list.add(xinlist);
					}
					return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	public int delxinwen(int cId) {
		return DBManager.executeUpdate("DELETE from detailsinfo where newsId="+cId);
	}
	public int addxin(Detailsinfo pc) {
		return DBManager.executeUpdate("INSERT into Detailsinfo VALUES(null,'"+pc.getNewsTitle()+"','"+pc.getNewsDetails()+"','"+pc.getNt()+"','"+pc.getConsultationId()+"')");
	}
	public List<Detailsinfo> getDet(String name){
		List<Detailsinfo> pcList = new ArrayList<Detailsinfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from Detailsinfo where NewsTitle = '"+name+"'");
			while (rs.next()) {
				int newsId = rs.getInt("newsId");
				int consultationId = rs.getInt("consultationId");
				String newsTitle = rs.getString("newsTitle");
				String newsDetails = rs.getString("newsDetails");
				String nt = rs.getString("nt");
				Detailsinfo pc = new Detailsinfo(newsId, newsTitle, newsDetails, consultationId, nt);
				pcList.add(pc);
			}
			return pcList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	/**
	 * 分页
	 * */
	
}
